﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChildrenDictionary
{
    Dictionary<string, GameObject> m_GMObjDict = new Dictionary<string, GameObject>();
    public void Init(GameObject obj)
    {
        m_GMObjDict.Clear();
        UITool.GetStaffDictionary(obj,m_GMObjDict);
    }
    public GameObject GetObj(string name)
    {
        return m_GMObjDict.ContainsKey(name)? m_GMObjDict[name]:null;
    }
    public T GetComponent<T>(string name, bool ifAddComponent = true) where T:Component
    {
        if (!m_GMObjDict.ContainsKey(name)) return null;
        GameObject target = m_GMObjDict[name];
        return target.GetComponent<T>() ?? (ifAddComponent? target.AddComponent<T>():null);
    }
}
